﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace GSManager
{
    public class DSHangGiaCong
    {
        private string _MaGiaCong;
        private string _MaThoGiaCong;
        private string _MoTa;
        private int _SoLuong;
        private decimal _DonGia;
        private decimal _ThanhTien;
        public string MaGiaCong
        {
            get { return _MaGiaCong; }
            set { _MaGiaCong = value; }
        }
        public string MaThoGiaCong
        {
            get { return _MaThoGiaCong; }
            set { _MaThoGiaCong = value; }
        }
        public string MoTa
        {
            get { return _MoTa; }
            set { _MoTa = value; }
        }
        public int SoLuong
        {
            get { return _SoLuong; }
            set { _SoLuong = value; }
        }
        public decimal DonGia
        {
            get { return _DonGia; }
            set { _DonGia = value; }
        }
        public decimal ThanhTien
        {
            get { return _ThanhTien; }
            set { _ThanhTien = value; }
        }
        public void ThemGiaCong()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "insert into GIACONG values(?,?,?,?,?,?)";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            cmd.Parameters.Add("@MaGiaCong", OleDbType.VarChar);
           
            cmd.Parameters.Add("@MoTa", OleDbType.VarWChar);
            cmd.Parameters.Add("@SoLuong", OleDbType.Integer);
            cmd.Parameters.Add("@DonGia", OleDbType.Decimal);
            cmd.Parameters.Add("@ThanhTien", OleDbType.Decimal);
            cmd.Parameters.Add("@MaThoGiaCong", OleDbType.VarChar);
            cmd.Parameters["@MaGiaCong"].Value = MaGiaCong;
           
            cmd.Parameters["@MoTa"].Value = MoTa;
            cmd.Parameters["@SoLuong"].Value = SoLuong;
            cmd.Parameters["@DonGia"].Value = DonGia;
            cmd.Parameters["@ThanhTien"].Value = ThanhTien;
            cmd.Parameters["@MaThoGiaCong"].Value = MaThoGiaCong;
            cmd.ExecuteNonQuery();
            connect.Close();
        }
        public DataSet LayDanhSach()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select * from GIACONG where MaThoGiaCong is null";
            OleDbDataAdapter adapter = new OleDbDataAdapter(sql, connect);
            DataSet ds = new DataSet();
            adapter.Fill(ds, "GIACONG");
            connect.Close();
            return ds;
        }
        public void CapNhat(string magiacong,string matho)
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "Update GIACONG set MaThoGiaCong='" + matho + "' where MaGiaCong='" + magiacong + "'";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            cmd.ExecuteNonQuery();
            connect.Close();
        }
        public int DemDS()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select Count(MaGiaCong) from GIACONG";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            OleDbDataReader r = cmd.ExecuteReader();
            int kq = 0;
            while (r.Read())
            {
                try
                {
                    kq = (int)r[0];
                }
                catch (Exception) { }
            }
            r.Close();
            connect.Close();
            return kq;
        }
    }
}
